# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname="msys2-w32api-headers"
pkgver=9.0.0.6128.07922837
pkgrel=1
pkgdesc="Win32 API headers for MSYS2 32bit toolchain"
arch=('i686' 'x86_64')
url="https://mingw-w64.sourceforge.io/"
license=('custom')
groups=('msys2-devel')
depends=()
makedepends=('git' 'mingw-w64-cross-gcc')
options=('staticlibs' '!buildflags')
_commit='0792283787cca8fc27dd38671107c791c87f4db3'
source=("mingw-w64"::"git+https://git.code.sf.net/p/mingw-w64/mingw-w64#commit=$_commit")
sha256sums=('SKIP')

MINGW_CHOST=${CARCH}-w64-mingw32

pkgver() {
  cd "${srcdir}/mingw-w64"
  local _major=$(head -n 16 mingw-w64-headers/crt/_mingw_mac.h | grep '__MINGW64_VERSION_MAJOR' | sed -e 's/.* //' | tr '\n' '.' | sed 's/.$/\n/')
  local _minor=$(head -n 16 mingw-w64-headers/crt/_mingw_mac.h | grep '__MINGW64_VERSION_MINOR' | sed -e 's/.* //' | tr '\n' '.' | sed 's/.$/\n/')
  local _rev=0
  printf "%s.%s.%s.%s.%s" ${_major} ${_minor} ${_rev} "$(git rev-list --count $_commit)" "$(git rev-parse --short $_commit)"
}

build() {
  cd ${srcdir}/mingw-w64/mingw-w64-headers

  ./configure \
     --build=${CHOST} \
     --host=${MINGW_CHOST} \
     --prefix=/usr \
     --enable-sdk=all \
     --enable-w32api \
     --with-default-win32-winnt=0x601

  make
}

package() {
  cd ${srcdir}/mingw-w64/mingw-w64-headers

  make DESTDIR=${pkgdir} install
}
